import React from 'react'

import { Upload, message, Button } from 'antd';
import { VideoCameraAddOutlined } from '@ant-design/icons';

import style from './style.module.css'

const PinOne = (props) => {
    // 子传父   解构出父组件传过来的函数
    let { AddUpload } = props

    // 名称不能跟props重复
    const propss = {
        name: 'file',
        action: '/api/getpinupload',
        headers: {
            authorization: 'authorization-text',
        },
        onChange(info) {
            if (info.file.status !== 'uploading') {
                // console.log(info.file, info.fileList);
                console.log(info.file.response.url, '7777');
                // console.log(info.file, info.fileList[0].response.url,'9999');

                AddUpload(info.file.response.url)
            }
            if (info.file.status === 'done') {
                message.success(`${info.file.name} 上传成功`);
            } else if (info.file.status === 'error') {
                message.error(`${info.file.name} 上传失败`);
            }
        },
    };



    return <div className={style.pinone_M}>
        <div className={style.pinone_main_M}>
            <span>选择商品图片：</span>
            <Upload {...propss}>
                <div className={style.pinone_header_M}>
                    <Button icon={<VideoCameraAddOutlined />}></Button>
                </div>
            </Upload>
        </div>
    </div>
}

export default PinOne